package bishi.qunaerlvxing;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/09/14 19:55
 */
public class three {

    public static void main(String[] args){
        int res = new three().solution(1, "cdcdsdcdscbaabc");
        System.out.println(String.valueOf(res));

    }


    /* Write Code Here */
    public int solution(int n, String str) {
        CountDownLatch cdl = new CountDownLatch(3);
        int res = 0;
        char[] cs = str.toCharArray();
        for(int i=0;i<cs.length;i++){
            char c = cs[i];
            List<int[]> list = new ArrayList<>();//{1,2}，当前结果下标为2，比较的下标为1，如果为false，则不是
            for(int j=i+2;j<cs.length;j++){
                List<int[]> list2 = new ArrayList<>();
                if(cs[j]==c){
                    list2.add(new int[]{i,j});
                }
                for(int[] is:list){
                    is[0]++;
                    if(cs[is[0]]!=cs[j])continue;
                    if(is[0]+2>=is[1]) {
                        res++;
                        System.out.println(is[1]);
                    }
                    else list2.add(is);
                }
                list = list2;
            }
        }
        return res;
    }
}
